package com.durian.availability.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.durian.common.log.annotation.Log;
import com.durian.common.log.enums.BusinessType;
import com.durian.common.security.annotation.RequiresPermissions;
import com.durian.system.api.domain.availability.RoomInfo;
import com.durian.availability.service.IRoomInfoService;
import com.durian.common.core.web.controller.BaseController;
import com.durian.common.core.web.domain.AjaxResult;
import com.durian.common.core.utils.poi.ExcelUtil;
import com.durian.common.core.web.page.TableDataInfo;

/**
 * 房源Controller
 *
 * @author durian
 * @date 2022-06-22
 */
@RestController
@RequestMapping("/availability")
public class RoomInfoController extends BaseController
{
    @Autowired
    private IRoomInfoService roomInfoService;

    /**
     * 查询房源列表
     */
    @RequiresPermissions("room:availability:list")
    @GetMapping("/list")
    public TableDataInfo list(RoomInfo roomInfo)
    {
        startPage();
        List<RoomInfo> list = roomInfoService.selectRoomInfoList(roomInfo);
        return getDataTable(list);
    }

    /**
     * 导出房源列表
     */
    @RequiresPermissions("room:availability:export")
    @Log(title = "房源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RoomInfo roomInfo)
    {
        List<RoomInfo> list = roomInfoService.selectRoomInfoList(roomInfo);
        ExcelUtil<RoomInfo> util = new ExcelUtil<RoomInfo>(RoomInfo.class);
        util.exportExcel(response, list, "房源数据");
    }

    /**
     * 获取房源详细信息
     */
    @RequiresPermissions("room:availability:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(roomInfoService.selectRoomInfoById(id));
    }

    /**
     * 新增房源
     */
    @RequiresPermissions("room:availability:add")
    @Log(title = "房源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RoomInfo roomInfo)
    {
        return toAjax(roomInfoService.insertRoomInfo(roomInfo));
    }

    /**
     * 修改房源
     */
    @RequiresPermissions("room:availability:edit")
    @Log(title = "房源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RoomInfo roomInfo)
    {
        return toAjax(roomInfoService.updateRoomInfo(roomInfo));
    }

    /**
     * 删除房源
     */
    @RequiresPermissions("room:availability:remove")
    @Log(title = "房源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(roomInfoService.deleteRoomInfoByIds(ids));
    }
}
